<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <title>销售任务列表</title>
    <!-- head 中 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.2/style/weui.min.css">
    <link href="${ctxStatic}/plugin/jquery-weui/lib/weui.min.css" type="text/css" rel="stylesheet"/>
    <link href="${ctxStatic}/plugin/jquery-weui/css/jquery-weui.css" type="text/css" rel="stylesheet"/>
</head>
<body ontouchstart ng-app="config" ng-controller="configCtrl" ng-init="init()">
<!-- body 顶部加上如下代码 -->
<div class="weui-pull-to-refresh__layer">
    <div class='weui-pull-to-refresh__arrow'></div>
    <div class='weui-pull-to-refresh__preloader'></div>
    <div class="down">下拉刷新</div>
    <div class="up">释放刷新</div>
    <div class="refresh">正在刷新</div>
</div>
<div class="weui-form-preview">
    <div class="weui-infinite-scroll">
        <div class="infinite-preloader">
            <div class="listview" ng-repeat="x in goodslist">
                <a href="${ctx}/sale/saleTask/form?id={{x.id}}">
                    <div class="weui-form-preview__bd">
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">任务名称</label>
                            <span class="weui-form-preview__value">{{x.taksName}}</span>
                        </div>
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">客户名称</label>
                            <span class="weui-form-preview__value">{{x.customerInformation.name}}</span>
                        </div>
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">状态</label>
                            <span class="weui-form-preview__value" ng-show="x.state==0">未发布</span>
                            <span class="weui-form-preview__value" ng-show="x.state==1">正常发布</span>
                            <span class="weui-form-preview__value" ng-show="x.state==2">已关闭</span>
                        </div>
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">责任人</label>
                            <span class="weui-form-preview__value">{{x.createBy.name}}</span>
                        </div>
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">完工时间</label>
                            <span class="weui-form-preview__value">{{x.completeTime}}</span>
                        </div>
                        <div class="weui-form-preview__item">
                            <label class="weui-form-preview__label">创建时间</label>
                            <span class="weui-form-preview__value">{{x.createDate}}</span>
                        </div>
                    </div>
                </a>
            </div>
            <div class="goodslist"></div>
            <div class="weui-loadmore">
                <i class="weui-loading"></i>
                <span class="weui-loadmore__tips">正在加载</span>
            </div>


            <%--<div class="weui-form-preview__ft">--%>
                <%--<a class="weui-form-preview__btn weui-form-preview__btn_default" href="javascript:">辅助操作</a>--%>
                <%--<button type="submit" class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:">--%>
                    <%--操作--%>
                <%--</button>--%>
            <%--</div>--%>
        </div>
    </div>
</div>
<!-- body 最后 -->
<script src="${ctxStatic}/plugin/jquery/jquery-2.1.4.js"></script>
<script src="${ctxStatic}/plugin/angular/angular.js"></script>
<scrip src="${ctxStatic}/plugin/jquery-validation/1.14.0/jquery.validate.js"></scrip>
<script src="${ctxStatic}/plugin/jquery-weui/lib/jquery-2.1.4.js"></script>
<script src="${ctxStatic}/plugin/jquery-weui/js/jquery-weui.js"></script>
<script src="${ctxStatic}/plugin/jquery-weui/lib/fastclick.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/list.js/1.5.0/list.min.js"></script>
<script>
    var app = angular.module('config', []);
    app.controller('configCtrl', function ($scope) {
        var pageFlag = 0
        var pageSize = 10
        $scope.init = function () {
            $scope.getGoodsList();//获取商品列表
        }
        $scope.getGoodsList = function () {
            var pageNo = 0
            $.ajax({
                url: "${ctx}/sale/saleTask/data",
                async: false,
                data: {"pageNo": pageNo, "pageSize": pageSize},
                type: "POST",
                success: function (respon) {
                    $scope.goodslist = respon.rows;
                }
            });
        };
        ///////////////////////////////////////////////////////////////////////


        $(document.body).pullToRefresh(function () {
            window.location.reload()
            // 下拉刷新触发时执行的操作放这里。
            // 从 v1.1.2 版本才支持回调函数，之前的版本只能通过事件监听
            $(document.body).pullToRefreshDone();
        });
        //上拉加载更多


        var loading = false;  //状态标记
        $(document.body).infinite(50).on("infinite", function () {
            pageFlag++;
            $.ajax({
                url: "${ctx}/sale/saleTask/data",
                async: false,
                data: {"pageNo": pageFlag, "pageSize": pageSize},
                type: "POST",
                success: function (respon) {
                    $scope.moreGoods = respon.rows;
                }
            });
            if (loading) return;
            loading = true;
            if ($scope.moreGoods.length > 0) {
                var list = $scope.moreGoods;
                setTimeout(function () {
                    for (var i = 0; i < list.length; i++) {
                        var statusName = "未发布";
                        if(list[i].state==1){
                            statusName = "正常发布";
                        }else if(list[i].state==2){
                            statusName = "已关闭";
                        }
                        var customerName = "";
                        if(list[i].customerInformation != null){
                            customerName = list[i].customerInformation.name;
                        }


                        var html = '<div class="addlistview" ng-repeat="x in moreGoods">' +
                            '<a href="${ctx}/sale/saleTask/form?id='+list[i].id + '">'+
                        '<div class="weui-form-preview__bd">' +
                        '<div class="weui-form-preview__item">' +
                        '<label class="weui-form-preview__label">任务名称</label>' +
                        '<span class="weui-form-preview__value">' + list[i].taksName + '</span>' +
                        '</div>' +
                        '<div class="weui-form-preview__item">' +
                        '<label class="weui-form-preview__label">客户名称</label>' +
                        '<span class="weui-form-preview__value">' + customerName + '</span>' +
                        '</div>' +
                        '<div class="weui-form-preview__item">' +
                        '<label class="weui-form-preview__label">状态</label>' +
                        '<span class="weui-form-preview__value">' + statusName + '</span>' +
                        '</div>' +
                        '<div class="weui-form-preview__item">' +
                        '<label class="weui-form-preview__label">责任人</label>' +
                        '<span class="weui-form-preview__value">' + list[i].createBy.name + '</span>' +
                        '</div>' +
                        '<div class="weui-form-preview__item">' +
                        '<label class="weui-form-preview__label">完工时间</label>' +
                        '<span class="weui-form-preview__value">' + list[i].completeTime + '</span>' +
                        '</div>' +
                        '<div class="weui-form-preview__item">' +
                        '<label class="weui-form-preview__label">创建时间</label>' +
                        '<span class="weui-form-preview__value">' + list[i].createDate + '</span>' +
                        '</div>' +
                        '</div>' +
                        '</a>' +
                        '</div>';
                        $(".goodslist").after(html);
                    }
                    loading = false;
                }, 1500);   //模拟延迟
            }
            else {
                $(document.body).destroyInfinite();//销毁加载插件
                alert("没有更多数据啦！")
            }

        });
    });
    /* $(function () {

     FastClick.attach(document.body);
     }); */


    //下拉刷新

</script>
</body>
</html>